package com.hxkj.controller;

import com.hxkj.domain.po.Article;
import com.hxkj.domain.po.Tags;
import com.hxkj.service.TagsService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @ClassName TagsController
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/6/7 11:57
 * @Version 1.0
 */
@RestController
@RequestMapping("/tags")
public class TagsController {

    @Autowired
    TagsService tagsService;

    /**
     * @author Mr.zheng
     * @Description saveTags 新增tags标签
     * @Date 12:22 2018/6/7
     **/
    @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> saveTags(@RequestBody Tags tags) throws Exception {
        return () -> tagsService.saveTags(tags);
    }

    /**
     * @author Mr.zheng
     * @Description getTagsList 获取tags标签列表
     * @Date 12:23 2018/6/7
     **/
    @RequestMapping(value = "/getlist", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultPageStruct<Tags>> getTagsList(@RequestBody ParameterDataStruct<Tags> parameterDataStruct) throws Exception {
        return () -> ResultStructUtils.buildResultPageStruct(tagsService.getTagsList(parameterDataStruct.getData() == null ?
                new Tags() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()));
    }

    /**
     * @author Mr.zheng
     * @Description getTags 根据条件获取tags标签
     * @Date 12:24 2018/6/7
     **/
    @RequestMapping(value = "/get", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<Tags> getTags(@RequestBody Tags tags) throws Exception {
        return () -> tagsService.getTags(tags);
    }

    /**
     * @author Mr.zheng
     * @Description removerTags 删除tags标签
     * @Date 12:24 2018/6/7
     **/
    @RequestMapping(value = "/remove", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> removeTags(@RequestBody Tags tags) throws Exception {
        return () -> tagsService.removeTags(tags);
    }

    /**
     * @author Mr.zheng
     * @Description modifyTags 修改tags标签
     * @Date 12:24 2018/6/7
     **/
    @RequestMapping(value = "/modify", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> modifyTags(@RequestBody Tags tags) throws Exception {
        return () -> tagsService.modifyTags(tags);
    }

    /**
     * @author Mr.zheng
     * @Description getShowTagsList 获取tags下拉框
     * @Date 15:20 2018/6/29
     **/
    @RequestMapping(value = "/getshowlist", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Tags>> getShowTagsList(@RequestBody Tags tags) throws Exception {
        return () -> tagsService.getShowTagsList(tags);

    }

    /**
     * @author Mr.zheng
     * @Description getQuoteCountTagsList 获取热点标签根据热点排序
     * @Date 8:51 2018/7/12
     **/
    @RequestMapping(value = "/getQuoteCountList", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Tags>> getQuoteCountTagsList(@RequestBody Tags tags) throws Exception {
        return () -> tagsService.getQuoteCountTagsList(tags);

    }

    /**
     * @author zzx
     * @Description getQuoteCountTagsList获取热度前 20 的tags标签
     * @Date 8:51 2018/7/12
     **/
    @RequestMapping(value = "/getTagsListByQuoteCount", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Tags>> getTagsListByQuoteCount(@RequestBody Tags tags) throws Exception {
        return () -> tagsService.getTagsListByQuoteCount(tags);

    }

    /**
     * @author zzx
     * @Description 根据tagId  查询文章列表
     * @Date 8:51 2018/7/12
     **/
    @RequestMapping(value = "/getArticleByTag", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Article>> getArticleByTag(@RequestBody Tags tags) throws Exception {
        return () -> tagsService.getArticleByTag(tags);

    }


    /**
     * @author Mr.zheng
     * @Description getHotTagsList 获取热词标签
     * @Date 11:59 2018/7/20
     **/
    @RequestMapping(value = "/getHotTagsList", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultPageStruct<Tags>> getHotTagsList(@RequestBody ParameterDataStruct<Tags> parameterDataStruct) throws Exception {
        return () -> ResultStructUtils.buildResultPageStruct(tagsService.getHotTagsList(parameterDataStruct.getData() == null ?
                new Tags() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()));
    }


    /**
     * @author Mr.zheng
     * @Description getHotArticleAsTagsList 获取热门文章的标签列表
     * @Date 11:59 2018/7/20
     **/
    @RequestMapping(value = "/getHotArticleAsTagsList", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<List<Tags>> getHotArticleAsTagsList(@RequestBody Article article) throws Exception {
        return () -> tagsService.getHotArticleAsTagsList(article);
    }
}
